//
//  HMHomeTableViewController.swift
//  sina
//
//  Created by Kent on 16/9/22.
//  Copyright © 2016年 Ming. All rights reserved.
//

import UIKit
import YYModel

private let statusCellID = "HMStatusCellID"

class HMHomeTableViewController: HMBaseTableViewController {
    
    var homeVM: HMHomeViewModel = HMHomeViewModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        tableView.register(HMStatusCell.self, forCellReuseIdentifier: statusCellID)
        
        tableViewSetup()

        navigationItem.rightBarButtonItem = UIBarButtonItem(imageName: "navigationbar_pop", target: self, action: #selector(push))
        
        loginView.updateInfo(content: "关注一些人,快回到这里看看有什么惊喜", imageName: nil)
        
        homeVM.loadData { (isSuccess) in
            if !isSuccess {
                showErrorSVP(isTrue: false)
                return
            }
            
            self.tableView.reloadData()
        }
        
    }
    
    func tableViewSetup() {
        tableView.separatorStyle = .none
        tableView.estimatedRowHeight = 2
        tableView.rowHeight = UITableViewAutomaticDimension
    }
    
    func push() {
        let temp = HMTempViewController()
        navigationController?.pushViewController(temp, animated: true)
    }
    
    

}

extension HMHomeTableViewController {
    
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return homeVM.statusViewModelArray.count
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: statusCellID, for: indexPath) as! HMStatusCell
        
        let vm = homeVM.statusViewModelArray[indexPath.row]
        
        cell.viewModel = vm
        
        return cell
    }
    
}

































